<!-- 首页的item项 --><template>
	<view class="friend_list" :style="toppingBgc"
	@tap="friendDetail">
		<view class="left_avatar">
			<image :src="data.avatar ? data.avatar : '/static/avatar/default_avatar.png'"			class="image"></image>
			<view class="tip" v-if="data.noreadnum">
				<tip :num="data.noreadnum"></tip>
			</view>
		</view>
		<view class="right_info">
			<view class="top">
				<text class="left item">{{data.name}}</text>
				<text class="right time item">{{time}}</text>
			</view>
			<view class="buttom">
				<text class="info item">{{data.data}}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { computed } from 'vue';
	import tip from '@/components/tip/tip.vue'
	import $T from '@/lib/time.js'
	import useUser from '@/pinia/user';
	import { setStorage } from '@/lib/storage';
	
	const userStore = useUser()
		const props = defineProps({		data:{			type: Object,			default: () => {}		}	})	// 计算时间	const time = computed(() =>{		return $T.gettime(props.data.update_time)	})
	// 置顶的背景颜色
	const toppingBgc = computed(() => {
		let topping = props.data.isTopping
		return topping ? `background-color: #f5f5f5` : 'background-color: #fff'
	})	// 进入信息详情页面	const friendDetail = () => {		let item = {			avatar: props.data.avatar,			nickname: props.data.name,			user_id: props.data.id,			username: props.data.name,
			chat_type: props.data.chat_type,
			isTopping: props.data.isTopping		}		uni.navigateTo({			url:'/pages/chat/chat?info=' + encodeURIComponent(JSON.stringify(item))		})
		// 更新脚标
		userStore.chatList.forEach(f => {
			if(f.id === props.data.id){
				f.noreadnum = 0
			}
		})
		let key = `chatlist_${userStore.userinfo.id}`
		setStorage(key, userStore.chatList)
		userStore.chat.updateBadge()	}
</script>

<style lang="less" scoped>
.friend_list{
	display: flex;
	flex-direction: row;
	padding: 10rpx 20rpx;
	background-color: #fff;
	.left_avatar{
		position: relative;
		width: 110rpx;
		height: 110rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		.tip{			width: 30rpx;			height: 30rpx;
			position: absolute;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			right: 0rpx;
			top: 0rpx;
			border-radius: 50%;
			background-color: red;
		}
		.image{
			width: 90rpx;
			height: 90rpx;
			border-radius: 15rpx;
		}
	}
	.right_info{
		flex: 1;
		display: flex;
		flex-direction: column;
		padding: 5rpx 10rpx;
		.item{
			font-size: 30rpx;
		}
		.top{
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			.time{
				font-size: 25rpx;
				color: #999;
			}
		}
		.buttom{
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: center;
			.info{
				color: #999;
			}
		}
	}
}
</style>